﻿using pbvs.Data.Repositories.Interfaces;
using pbvs.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace pbvs.Data.Repositories
{
    public class FormElementRepository : IFormElementRepository
    {
        private readonly PbvsContext _db;
        public FormElementRepository(PbvsContext db)
	    {
            _db = db;
	    }
        public IQueryable<FormElement> Elements { get { return _db.FormElements; } }
        public void Add(FormElement elem)
        {
            _db.FormElements.Add(elem);
        }

        public void Update(FormElement elem)
        {
            FormElement dbElem = _db.FormElements.Find(elem.Field);
            if (dbElem != null)
            {
                dbElem.HelpText = elem.HelpText;
            }
        }

        public int Save()
        {
            return _db.SaveChanges();
        }
    }
}